
export const setDb = (k, value) => {
  localStorage.setItem(k, value)
}
export const getDb = k => {
  return localStorage.getItem(k)
}
export const removeDb = k => {
  return localStorage.removeItem(k)
}
// 深拷贝
export const deepCopy = obj => {
  return JSON.parse(JSON.stringify(obj))
}
// 车牌号的正则
export const regCarNum = /^(([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z](([0-9]{5}[DF])|([DF]([A-HJ-NP-Z0-9])[0-9]{4})))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳使领]))$/
// 航班号的正则
export const regPlayNum = /^[A-Z0-9]{5,6}$/
// 手机号的正则
export const regPhone = /^1(3|4|5|6|7|8|9)\d{9}$/
// 银行卡的正则
export const regBankCard = /^([1-9]{1})(\d{14}|\d{18})$/
// 获得日期的时间戳
export const getTimes = (day) => {
  return Date.parse(new Date(day))
}

// 主动触发窗口变化事件，让图表根据窗口变化而自适应
export const resetView = () => {
  if (document.createEvent) {
      const event = document.createEvent('HTMLEvents')
      event.initEvent('resize', true, true)
      window.dispatchEvent(event)
  } else if (document.createEventObject) {
      window.fireEvent('onresize')
  }
}
// 获取日期时分秒
export const getDays = (times, states = true) => {
  let date = times ? new Date(times) : new Date()
  let year = date.getFullYear()
  let month = date.getMonth() + 1 < 10 ? `0${date.getMonth() + 1}` : date.getMonth() + 1 < 10
  let days = date.getDate() < 10 ? `0${date.getDate()}` : date.getDate()
  if (states) {
    return `${year}-${month}-${days}`
  } else {
    return `${month}-${days}`
  }
}
export const getYMD = date => {
  const year = date.getFullYear()
  let month = date.getMonth() + 1
  let day = date.getDate()
  month = month < 10 ? `0${month}` : month
  day = day < 10 ? `0${day}` : day
  return `${year}-${month}-${day}`
}
export const getYMDHSM = date => {
  const year = date.getFullYear()
  let month = date.getMonth() + 1
  let day = date.getDate()
  month = month < 10 ? `0${month}` : month
  day = day < 10 ? `0${day}` : day
  let h = date.getHours() < 10 ? `0${date.getHours()}` : date.getHours()
  let m = date.getMinutes() < 10 ? `0${date.getMinutes()}` : date.getMinutes()
  let s = date.getSeconds() < 10 ? `0${date.getSeconds()}` : date.getSeconds()
  return `${year}-${month}-${day} ${h}:${m}:${s}`
}
// 百度地图坐标转化为高德地图坐标
export const baiduMapTrunGaoDe = (lat, lng) => {
  let X_PI = Math.PI * 3000.0 / 180.0
  let x = lng - 0.0065
  let y = lat - 0.006
  let z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * X_PI)
  let theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * X_PI)
  let gg_lng = z * Math.cos(theta);
  let gg_lat = z * Math.sin(theta);
  return {lat: gg_lat, lng: gg_lng}
}

// 高德地图坐标转化为百度地图坐标
export const gaoDeMpaTrunBaiDu = (lat, lng) => {
  let X_PI = Math.PI * 3000.0 / 180.0;
  let x = lng, y = lat
  let z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * X_PI)
  let theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * X_PI)
  let gg_lng = z * Math.cos(theta) + 0.0065
  let gg_lat = z * Math.sin(theta) + 0.006
  return {lng: gg_lng, lat: gg_lat}
}
